package com.db.stexchem.message;

public class Order extends Data{

  private String stockName;
  private Operation operation;
  private int nShares;
  private Float price;
  private int orderNo;
  private OrderType orderType = OrderType.MARKET;
  private String party;
  private boolean fullyFilled = true;
  
  public Order() {
  }

  public String getStockName() {
    return stockName;
  }

  public void setStockName(String stockName) {
    this.stockName = stockName;
  }

  public Operation getOperation() {
    return operation;
  }

  public void setOperation(Operation operation) {
    this.operation = operation;
  }

  public int getNShares() {
    return nShares;
  }

  public void setNShares(int nShares) {
    this.nShares = nShares;
  }

  public Float getPrice() {
    return price;
  }

  public void setPrice(float price) {
    this.orderType = OrderType.LIMIT;
    this.price = price;
  }

  public int getOrderNo() {
    return orderNo;
  }

  public void setOrderNo(int orderNo) {
    this.orderNo = orderNo;
  }

  public OrderType getOrderType() {
    return orderType;
  }

  public void setOrderType(OrderType orderType) {
    if (orderType == OrderType.MARKET) {
      price = null;
    } else if (price == null){
      price = Float.valueOf(0);
    }
    this.orderType = orderType;
  }

  public String getParty() {
    return party;
  }

  public void setParty(String party) {
    this.party = party;
  }

  public boolean isFullyFilled() {
    return fullyFilled;
  }

  public void setFullyFilled(boolean fullyFilled) {
    this.fullyFilled = fullyFilled;
  }

  @Override
  public boolean equals(Object obj) {
    if (this == obj)
      return true;
    if (obj == null)
      return false;
    if (getClass() != obj.getClass())
      return false;
    Order other = (Order) obj;
    if (nShares != other.nShares)
      return false;
    if (operation != other.operation)
      return false;
    if (orderType != other.orderType)
      return false;
    if (price == null) {
      if (other.price != null)
        return false;
    } else if (!price.equals(other.price))
      return false;
    if (stockName == null) {
      if (other.stockName != null)
        return false;
    } else if (!stockName.equals(other.stockName))
      return false;
    return true;
  }

  @Override
  public String toString() {
    return "Order [stockName=" + stockName + ", operation=" + operation
        + ", nShares=" + nShares + ", price=" + price + ", orderNo=" + orderNo
        + ", orderType=" + orderType + ", party=" + party + ", fullyFilled="
        + fullyFilled + "]";
  }

  
}
